package ar.org.cfired.creditos;
//import org.jbpm.api.Configuration;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.jbpm.api.Execution;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.api.*;
import org.jbpm.api.task.*;
import org.jbpm.pvm.internal.task.TaskImpl;

import ar.org.cfired.creditos.Importes;
import ar.org.cfired.creditos.gui.Funcionalidad;
import ar.org.cfired.hibernate.utils.HibernateUtil;
public class PruebaImportes {
	public static void main (String args[]) {
		System.out.println(Importes.toText("12501,00", true) + " Exception\n");
		System.out.println(Double.valueOf("12501.10"));
		//System.out.println(Integer.valueOf("12501.00"));
		ProcessEngine processEngine = new Configuration().buildProcessEngine();
		TaskService taskService = processEngine.getTaskService();
		ExecutionService  executionService = processEngine.getExecutionService();
		Task tarea = taskService.getTask("8539");
		String taskID = tarea.getId();	
		System.out.println(tarea.getActivityName());
		System.out.println(tarea.getClass().getName());
		//System.exit(0);
		
		 
			 System.out.println("VOY A SUSPENDERLA");
			 try {
				 ((TaskImpl)tarea).suspend();
				 
				Execution ex = executionService.findExecutionById(tarea.getExecutionId());
				ExecutionImpl imp = (ExecutionImpl)ex;
				  
				System.out.println("Estadio previo: " + imp.getState());
				System.out.println("Estadio ant: " + ex.getState());
				imp.suspend();
				//imp.signal();
				//imp.proceed();
				
				//ex.notify();
				System.out.println("Estadio posterior: " + ex.getState());
				taskService.saveTask(tarea);
				
				System.out.println("Estadio posterior: " + imp.getState());
				
				//System.out.println("Estado final: " + executionService.findExecutionById(tarea.getExecutionId()).getState());
			 
			 
				Transaction t;
				List<Funcionalidad> respuesta;
				Session session = HibernateUtil.getSessionFactory().getCurrentSession();
				t = session.beginTransaction();
				respuesta = (List<Funcionalidad>) session.createQuery("from Funcionalidad where estado='Designacion de Sectorialista' and perfil = 'E' order by secuencia").list();
				Funcionalidad f = respuesta.get(0);
				System.out.println(f.getVariable().toString() + "!!");
			 
			 }
			 catch (Exception e) {
				 e.printStackTrace();
			 }
	
	
	
	
	}
}
